//
//  WelcomeViewController.swift
//  新浪weibo
//
//  Created by test on 15/8/2.
//  Copyright © 2015年 test. All rights reserved.
//

import UIKit
import SDWebImage
class WelcomeViewController: UIViewController {
    
    private var iconBottomCons: NSLayoutConstraint?
    override func viewDidLoad() {
        super.viewDidLoad()
        
        prepareUI()

        if let urlString = UserAccount.sharedUserAccount?.avatar_large {
        iconView.sd_setImageWithURL(NSURL(string: urlString)!)
        
        }
        
    }
    
    override func viewDidAppear(animated: Bool) {
       
        super.viewDidAppear(animated)
        iconBottomCons?.constant = UIScreen.mainScreen().bounds.height - iconBottomCons!.constant
        
        UIView.animateWithDuration(1.2, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 5.0, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
             
                NSNotificationCenter.defaultCenter().postNotificationName(ZYRootViewControllerSwitchNotification, object: true)
                
        }
    
    
    }
    
    
    
    private func prepareUI() {
        view.addSubview(backImageView)
        view.addSubview(iconView)
        view.addSubview(lable)
        
        // 自动布局
        // 1> 背景图片
        backImageView.ff_Fill(view)
       
        
        
        // 2> 头像
        let cons = iconView.ff_AlignInner(type: ff_AlignType.BottomCenter, referView: view, size: CGSize(width: 90, height: 90), offset: CGPoint(x: 0, y: -160))
        // 记录底边约束
        iconBottomCons = iconView.ff_Constraint(cons, attribute: NSLayoutAttribute.Bottom)
        
        // 3> 标签
        lable.ff_AlignVertical(type: ff_AlignType.BottomCenter, referView: iconView, size: nil, offset: CGPoint(x: 0, y: 16))
    
    
    
    }
    
    
   private lazy var backImageView: UIImageView = UIImageView(image:UIImage(named: "ad_background"))
   private lazy var iconView:UIImageView = {
        let iv = UIImageView(image: UIImage(named: "avatar_default_big"))
        iv.layer.masksToBounds = true
        iv.layer.cornerRadius = 45
        
        
        return iv
        
        }()
    private lazy var lable: UILabel = {
    let lable = UILabel()
        lable.text = "欢迎回来"
        lable.sizeToFit()
    return lable
    
    }()
    
    
    

    

}
